package main

import (
	"fmt"
	"gorm-study/src/pkg/student/models"
	"gorm-study/src/pkg/utils/dbutil"
)

func main() {
	students := []models.Student{
		{
			Name:   "李四",
			Age:    24,
			Gender: true,
			Email: func() *string { // 只能通过这种方式为 *string 类型的 Email 赋值，否则就要像插入单条那样，在外面定义一个变量，再获取变量地址
				email := "lisi@163.com"
				return &email
			}(),
		},
		{
			Name:   "王五",
			Age:    25,
			Gender: true,
			Email: func() *string {
				email := "wangwu@163.com"
				return &email
			}(),
		},
	}

	result := dbutil.DB.Create(&students)

	fmt.Printf("插入的条数：%v \n", result.RowsAffected)
	for _, student := range students {
		fmt.Printf("%v 生成的主键ID：%v \n", student.Name, student.ID)
	}

}
